// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 * TEMPLATE:    SpringServiceImpl.vsl in andromda-spring cartridge
 * MODEL CLASS: AndroMDAModel::JR Appointment Service::com.systemsjr.jrappointment::appointment::service::AppointmentService
 * STEREOTYPE:  Service
 */
package com.systemsjr.jrenterprise.appointment.service;

import java.util.Collection;

import com.systemsjr.jrenterprise.appointment.Appointment;
import com.systemsjr.jrenterprise.appointment.AppointmentDao;
import com.systemsjr.jrenterprise.appointment.vo.AppointmentSearchCriteria;
import com.systemsjr.jrenterprise.appointment.vo.AppointmentVO;

/**
 * @see com.systemsjr.jrappointment.appointment.service.AppointmentService
 */
public class AppointmentServiceImpl
    extends AppointmentServiceBase
{

   
    /**
     * @see com.systemsjr.jrappointment.appointment.service.AppointmentService#loadAll()
     */
    protected  Collection handleLoadAll()
        throws Exception
    {
    	return getAppointmentDao().loadAll(AppointmentDao.TRANSFORM_APPOINTMENTVO);
    }

	@Override
	protected void handleDelete(AppointmentVO appointmentVO) throws Exception {
		// TODO Auto-generated method stub
		if(appointmentVO.getId() != null){
			getAppointmentDao().remove(appointmentVO.getId());
		}
	}

	@Override
	protected AppointmentVO handleSave(AppointmentVO appointmentVO)
			throws Exception {
		Appointment appointment = getAppointmentDao().appointmentVOToEntity(appointmentVO);
		
		if(appointmentVO.getId() == null){
			appointment = getAppointmentDao().create(appointment);
		} else{
			getAppointmentDao().update(appointment);
		}
		
		return getAppointmentDao().toAppointmentVO(appointment);
	}

	@Override
	protected Collection<AppointmentVO> handleSearch(AppointmentSearchCriteria searchCriteria)
			throws Exception {
		Collection<Appointment> list = getAppointmentDao().findByCriteria(searchCriteria);
		
		return getAppointmentDao().toAppointmentVOCollection(list);
	}

}